//弹出选择框选择系统预置页面URL
fmdmeta_prop.func.selectPopupUrl=function(rId, cInd){
	var w1 = fm_createCenterWindow('wid_selectPopupUrl',fmd_i18n_prop_selectPopupPage, 800, 600);

	var lo1 = w1.attachLayout("2E");
	lo1.cells('a').hideHeader();
	lo1.cells('b').hideHeader();
	lo1.cells('b').setHeight(50);
	var stb1 = lo1.cells('a').attachStatusBar();
	stb1.setText("<div id='id_paging_selectUri'></div>");
			
	var str1 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"333":"343"), offsetTop:"0", 
			list:[{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:10}]}];
	var fm2 = lo1.cells('b').attachForm(str1);
	var uriq = {};
	uriq.rest_query = fmdCtx + "/rest/popup/queryUrl";
	
	//grid
	var ragrid = lo1.cells('a').attachGrid();
	ragrid.setHeader([fmd_i18n_l_no,
                    'id',
					fmd_i18n_prop_selectPageName,
					fmd_i18n_prop_selectPageUri],
                    null,
                    ["text-align:center;",
                     "text-align:center;",
                     "text-align:center;",
                     "text-align:center;"]);
	ragrid.attachHeader("#rspan,#rspan,#rspan,#rspan");
	ragrid.setInitWidths("40,10,200,520");
	ragrid.setColumnIds("NO,id,name,url");
	ragrid.setColTypes("ro,ro,ro,ro");
	ragrid.setColSorting("na,na,na,na");
	ragrid.setColAlign("center,center,center,left");
	ragrid.setLang(fmdmeta_prop.lang);
	ragrid.setEditable(false);
	ragrid.init();
	ragrid.setColumnHidden('1',true);
//		ragrid._grid_ordercolumns = [{"TYPE":"ASC"}];
	
	//paging
	ragrid.setPagingWTMode(true,true,true,[20,50,100]);
	ragrid.enablePaging(true,20,5,'id_paging_selectUri');
	ragrid.setPagingSkin("toolbar", dhx_skin);
	
	ragrid.attachEvent("onPageChanged", function(ind,fInd,lInd){
		quri_toPage(fInd+1, lInd);
	});
	
	ragrid.attachEvent("onRowDblClicked", function(rid,cid){
		var id = ragrid.cells(rid, 1).getValue();
		var name = ragrid.cells(rid, 2).getValue();
		var url = ragrid.cells(rid, 3).getValue();
		var newval = {"realValue":url, "displayValue":name};
		fmdc.grid_prop.cells(rId, cInd).setValue(newval, true);	//第二个参数必须为true，触发事件
		w1.close();
	});
	
	fm2.attachEvent("onButtonClick", function(btid) {
		if (btid=='fb_ok') {
			var rid = ragrid.getSelectedRowId();
			if (!rid) {
				msg(fmd_i18n_msg_sel);
				return;
			}
			var id = ragrid.cells(rid, 1).getValue();
			var name = ragrid.cells(rid, 2).getValue();
			var url = ragrid.cells(rid, 3).getValue();
			var newval = {"realValue":url, "displayValue":name};
			fmdc.grid_prop.cells(rId, cInd).setValue(newval, true);	//第二个参数必须为true，触发事件
			w1.close();
		}
	});

	quri_toPage(1, 20);
	
	//query
	function quri_toPage(fromRow, toRow){
		lo1.cells('b').progressOn();
		var p = { "fromRow":fromRow, "toRow":toRow, "timezoneOffset":new Date().getTimezoneOffset(),
				"ordercolumns":JSON.stringify(ragrid._grid_ordercolumns)};
		var ret = doPostSyncJson(uriq.rest_query, p);
		if (!ret) {
			lo1.cells('b').progressOff();
			msgErr(fmd_i18n_msg_readfail);
			return;
		}
		ragrid.clearAllInPaging();
		ragrid.parse(ret, "json");
		lo1.cells('b').progressOff();
	}
};

fmdmeta_prop.func.selectModelForModelSelect = function(rId, cId) {
	var w1 = fm_createCenterWindow('wid_selectModelForModelSelect',fmd_i18n_modules.popupinput.modelselectmodel, 600, 500);

	var lo1 = w1.attachLayout("2E");
	lo1.cells('a').hideHeader();
	lo1.cells('b').hideHeader();
	lo1.cells('b').setHeight(50);
	var stb1 = lo1.cells('a').attachStatusBar();
	stb1.setText("<div id='id_paging_selectModel'></div>");
			
	var str1 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"233":"243"), offsetTop:"0", 
			list:[{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:10}]}];
	var fm2 = lo1.cells('b').attachForm(str1);
	var uriq = {};
	uriq.rest_query = fmdCtx + "/rest/bo/query";
	
	//grid
	var ragrid = lo1.cells('a').attachGrid();
	ragrid.setHeader([fmd_i18n_l_no,
                    'boid',
                    fmd_i18n_modules.popupinput.modelselectmodel,
                    fmd_i18n_modules.popupinput.modelselectmodeldesc],
                    null,
                    ["text-align:center;",
                     "text-align:center;",
                     "text-align:center;",
                     "text-align:center;"]);
	ragrid.attachHeader("#rspan,#rspan,"+
			"<input id='sr_boname' type='text' style='width:90%'/>,"+
			"<input id='sr_bodesc' type='text' style='width:90%'/>");
	ragrid.setInitWidths("40,10,160,*");
	ragrid.setColumnIds("NO,id,name,desc");
	ragrid.setColTypes("ro,ro,ro,ro");
	ragrid.setColSorting("na,na,str,str");
	ragrid.setColAlign("center,center,left,left");
	ragrid.setLang(fmdmeta_prop.lang);
	ragrid.setEditable(false);
	ragrid.init();
	ragrid.setColumnHidden('1',true);
	ragrid._grid_ordercolumns = [{"CREATETIME":"DESC"}];
	
	//paging
	ragrid.setPagingWTMode(true,true,true,[10,20,50]);
	ragrid.enablePaging(true,10,5,'id_paging_selectModel');
	ragrid.setPagingSkin("toolbar", dhx_skin);
	
	ragrid.attachEvent("onPageChanged", function(ind,fInd,lInd){
		quri_toPage(fInd+1, lInd);
	});
	//header click event
	ragrid.attachEvent("onHeaderClick", grid_onHeaderClick);
	
	ragrid.attachEvent("onRowDblClicked", function(rid,cid){
		rtnValue(rid);
	});
	
	fm2.attachEvent("onButtonClick", function(btid) {
		if (btid=='fb_ok') {
			var rid = ragrid.getSelectedRowId();
			if (!rid) {
				msg(fmd_i18n_msg_sel);
				return;
			}
			rtnValue(rid);
		}
	});

	quri_toPage(1, 10);
	
	//return
	function rtnValue(rid) {
		var id = ragrid.cells(rid, 1).getValue();
		var name = ragrid.cells(rid, 2).getValue();
		var desc = ragrid.cells(rid, 3).getValue();
		var newval = {"id":id, "realValue":name, "displayValue":name+"["+desc+"]"};
		fmdc.grid_prop.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
		w1.close();
	}
	
	//bind header query action
	var trsr_versionname = $("#sr_boname").parents('tr:first');
	trsr_versionname.find('td').bind('click',utp_stopEvent);
	trsr_versionname.find('td').bind('mouseover',utp_stopEvent);
	$("#sr_boname").bind('keypress', bom_enterQuery);
	$("#sr_bodesc").bind('keypress', bom_enterQuery);
	
	function bom_enterQuery(e) {
		if (e.keyCode==13) {
			uriq.boquery_boname = $.trim($("#sr_boname").val());
			uriq.boquery_bodesc = $.trim($("#sr_bodesc").val());
			
			quri_toPage(1, 10);
		}
	}
	
	//stop event propagation
	function utp_stopEvent(e){
		if (e && e.stopPropagation!=undefined) {
			e.stopPropagation();
		} else if (window.event){
			window.event.cancelBubble = true;
		}
		return false;
	}
	
	//query
	function quri_toPage(fromRow, toRow){
		lo1.cells('b').progressOn();
		var p = {"queryParams":{"purpose":"1"}, "fromRow":fromRow, "toRow":toRow, "timezoneOffset":new Date().getTimezoneOffset(),
				"ordercolumns":JSON.stringify(ragrid._grid_ordercolumns)};
		uriq.boquery_boname && (p.queryParams.boname = uriq.boquery_boname);
		uriq.boquery_bodesc && (p.queryParams.bodesc = uriq.boquery_bodesc);
		p.queryParams = JSON.stringify(p.queryParams);
		var ret = doPostSyncJson(uriq.rest_query, p);
		if (!ret) {
			lo1.cells('b').progressOff();
			msgErr(fmd_i18n_msg_readfail);
			return;
		}
		ragrid.clearAllInPaging();
		ragrid.parse(ret, "json");
		lo1.cells('b').progressOff();
	}
};

fmdmeta_prop.func.selectModelListForModelSelect = function(rId, cId) {
	//检查是否选定了数据绑定
	var modelName = fmdc.version.formdata.propconf[designer.getSelected().attr("id")]["dataprovider-modelselectmodel"];
	if (!modelName) {
		msg(fmd_i18n_modules.popupinput.msg_plsselmodel);
		return;
	}
	var model = doGetSyncJson(fmdCtx + "/rest/bo/getByName/"+modelName);
	
	var w1 = fm_createCenterWindow('wid_selectModelListForModelSelect', fmd_i18n_modules.popupinput.modelselectmodellist, 800, 600);
	
	var lo1 = w1.attachLayout("2E");
	lo1.cells('a').hideHeader();
	lo1.cells('b').hideHeader();
	lo1.cells('b').setHeight(60);
	
	var str1 = [{ type:"block" , name:"form_block_1", offsetLeft:(dhx_skin=="dhx_web"?"333":"343"), offsetTop:"0", 
			list:[{ type:"button" , name:"fb_ok", value:fmd_i18n_b_ok, inputTop:10}]}];
	var fm2 = lo1.cells('b').attachForm(str1);
	
	//grid
	var ragrid = lo1.cells('a').attachGrid();
	ragrid.extIconPath = resloc + fmdmeta_prop.gridconf.extIconPath;
	ragrid.setHeader([fmd_i18n_l_no,
	                    fmd_i18n_modules.dhxgrid.colname,
						fmd_i18n_modules.dhxgrid.coltype,
						fmd_i18n_modules.popupinput.modelselectmodellistheader,
						"#cspan",
						fmd_i18n_modules.dhxgrid.colmeta,
						fmd_i18n_modules.dhxgrid.colmetasource,
						fmd_i18n_modules.dhxgrid.hidden,
						fmd_i18n_modules.dhxgrid.width,
						fmd_i18n_modules.dhxgrid.align,
						fmd_i18n_modules.dhxgrid.sort,
						fmd_i18n_modules.dhxgrid.order,
						fmd_i18n_modules.dhxgrid.format,
						fmd_i18n_modules.popupinput.searchcondition,
						fmd_i18n_modules.popupinput.realValue,
						fmd_i18n_modules.popupinput.displayValue
						],
	                    null,
	                    ["text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;",
	                     "text-align:center;"]);
	ragrid.attachHeader("#rspan,#rspan,#rspan,"+fmd_i18n_modules.dhxgrid.zh+","+fmd_i18n_modules.dhxgrid.en+",#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan,#rspan");
	ragrid.setInitWidths("40,100,60,120,120,80,100,45,45,60,80,80,80,80,80,80");
	ragrid.setColumnIds("NO,NAME,TYPE,ZH,EN,META,METASOURCE,HIDDEN,WIDTH,ALIGN,SORT,ORDER,FORMAT,SEARCH,RV,DV");
	ragrid.setColTypes("ro,ro,ro,ed,ed,ro,ro,ch,ed,ro,ro,ed,ro,roch,ra,ra");
	ragrid.setColSorting("na,na,na,na,na,na,na,na,na,na,na,na,na,na,na,na");
	ragrid.setColumnsVisibility("false,false,false,false,false,false,false,false,false,false,true,true,true,false,false,false");
	ragrid.setColAlign("center,center,left,left,left,left,left,center,right,center,center,right,center,center,center,center");
	ragrid.setLang(fmdmeta_prop.lang);
	ragrid.setEditable(fmdc.grid_prop.isEditor);
	ragrid.isEditor = fmdc.grid_prop.isEditor;
	ragrid.enableValidation(fmdc.grid_prop.isEditor,fmdc.grid_prop.isEditor);
	ragrid.enableEditEvents(fmdc.grid_prop.isEditor,false,false);
	ragrid.enableDragAndDrop(fmdc.grid_prop.isEditor);
	ragrid.init();
	
	var idxTYPE=2;
	var idxZH=3;
	var idxEN=4;
	var idxMETA=5;
	var idxMETASOURCE=6;
	var idxHIDDEN=7;
	var idxWIDTH=8;
	var idxALIGN=9;
	var idxSORT=10;
	var idxORDER=11;
	var idxFORMAT=12;
	var idxSEARCH=13;
	var idxRV=14;
	var idxDV=15;
	
	//重置序号
	ragrid.attachEvent("onDrop", function(sId,tId,dId,sObj,tObj,sCol,tCol){
		var rn = this.getRowsNum();
		for (var i=0; i<rn; i++) {
			this.cellByIndex(i, 0).setValue(i+1);
		}
	});
	
	fm2.attachEvent("onButtonClick", function(btid) {
		if (btid=='fb_ok') {
			//realValue column checked?
			var crs = ragrid.getCheckedRows(idxRV);
			if (!crs) {
				msg(fmd_i18n_modules.popupinput.msg_plsselrv);return;
			}
			//displayValue column checked?
			crs = ragrid.getCheckedRows(idxDV);
			if (!crs) {
				msg(fmd_i18n_modules.popupinput.msg_plsseldv);return;
			}
			
			var newval = [];
			var rn = ragrid.getRowsNum();
			var valid = true;
			for (var i=0; i<rn; i++) {
				var rid = ragrid.getRowId(i);
				//验证所有列
				for (var j=3; j<=idxORDER; j++) {
					if (ragrid.cells(rid, j).getAttribute("validate") && !ragrid.validateCell(rid, j)) {
						valid = false;
					}
				}
				var r = {};
				r.id = rid;
				r.type = model.attrs[rid].type;
				r.zh = ragrid.cells(rid, idxZH).getValue();
				r.en = ragrid.cells(rid, idxEN).getValue();
				r.meta = ragrid.cells(rid, idxMETA).getValue();
				r.metasource = ragrid.cells(rid, idxMETASOURCE).getValue();
				r.hidden = ragrid.cells(rid, idxHIDDEN).getValue();
				r.width = ragrid.cells(rid, idxWIDTH).getValue();
				r.align = ragrid.cells(rid, idxALIGN).getValue();
				r.sort = ragrid.cells(rid, idxSORT).getValue();
				r.order = ragrid.cells(rid, idxORDER).getValue();
				r.format = ragrid.cells(rid, idxFORMAT).getValue();
				r.search = ragrid.cells(rid, idxSEARCH).getValue();
				r.rv = ragrid.cells(rid, idxRV).getValue();
				r.dv = ragrid.cells(rid, idxDV).getValue();
				newval.push(r);
			}
			if (!valid) {
				msg(fmd_i18n_modules.dhxgrid.msg_validateErr);
				return;
			}
			fmdc.grid_prop.cells(rId, cId).setValue(newval, true);	//第二个参数必须为true，触发事件
			w1.close();
		}
	});
	
	//已有数据
	var existingData = fmdc.version.formdata.propconf[designer.getSelected().attr("id")]["dataprovider-modelselectlist"];
	var ov = typeof(existingData)=='string' ? JSON.parse(existingData) : existingData;
	
	//加载顺序应该按已有数据的既定顺序，如果不存在既定顺序再按照默认顺序
	var attrInOrder = [];	//排序模型属性的数组
	if (!MyUtilJs.isEmpty(ov)) {
		var temp1 = {};
		for (var c in model.attrs) {
			temp1[c] = true;
		}
		for (var i in ov) {
			if (temp1[ov[i].id]) {//如果属性在模型中有，则添加到排序数组
				attrInOrder.push(ov[i].id);
				delete temp1[ov[i].id];//添加过的删除
			}
		}
		for (var c in temp1) {	//没有配置过的属性，增加到最后
			attrInOrder.push(c);
		}
	} else {
		for (var c in model.attrs) {
			attrInOrder.push(c);
		}
	}
	
	//加载模型所有列
	var colorro = "#f6fcff";
	var colored = "#ffffff";
	var rownum = 1;
	for (var i in attrInOrder) {
		var c = attrInOrder[i];
		var type = model.attrs[c].type;
		ragrid.addRow(c, [rownum++, c, fmd_i18n_modules.dhxgrid.enu1names[type], model.attrs[c].desc_zh, model.attrs[c].desc_en,
		                  null, null, 0, null, null, null, null, null, null, null, null]);
		ragrid.setRowColor(c, colorro);
		ragrid.cells(c, idxZH).setBgColor(colored);
		ragrid.cells(c, idxEN).setBgColor(colored);
		ragrid.cells(c, idxHIDDEN).setBgColor(colored);
		ragrid.cells(c, idxWIDTH).setBgColor(colored);
		ragrid.cells(c, idxALIGN).setBgColor(colored);
		ragrid.cells(c, idxSORT).setBgColor(colored);
//		ragrid.cells(c, idxMETA).setBgColor(colored);
//		ragrid.cells(c, idxMETASOURCE).setBgColor(colored);
		ragrid.cells(c, idxORDER).setBgColor(colored);
		ragrid.cells(c, idxSEARCH).setBgColor(colorro);
		ragrid.cells(c, idxRV).setBgColor(colored);
		ragrid.cells(c, idxDV).setBgColor(colored);
		ragrid.cells(c, idxZH).setAttribute("validate", "NotEmpty");
//		ragrid.cells(c, idxEN).setAttribute("validate", "NotEmpty");
		ragrid.cells(c, idxWIDTH).setAttribute("validate", "ValidPositiveInteger");
		//ragrid.cells(c, idxORDER).setAttribute("validate", "ValidPositiveInteger");
		//bind editor by type
		switch(type) {
			case "string":
				//width
				ragrid.cells(c, idxWIDTH).setValue(100);
				//align
				ragrid.grid_bindCombo(c, idxALIGN, 
						[["left", fmd_i18n_modules.dhxgrid.enualign_left],["right",fmd_i18n_modules.dhxgrid.enualign_right],["center",fmd_i18n_modules.dhxgrid.enualign_center]], 
						{"comboSize":10, "comboWidth": 120}, 
						"left");
				//sorting
				ragrid.grid_bindCombo(c, idxSORT, 
						[["na", fmd_i18n_modules.dhxgrid.enusort_no],["int",fmd_i18n_modules.dhxgrid.enusort_int],["str",fmd_i18n_modules.dhxgrid.enusort_str]], 
						{"comboSize":10, "comboWidth": 120}, 
						"str");
				//meta
				ragrid.grid_bindCombo(c, idxMETA, 
						[["none", fmd_i18n_modules.dhxgrid.none],["dataprovider-dict", fmd_i18n_modules.dhxgrid.dict],["dataprovider-restsrv",fmd_i18n_modules.dhxgrid.restsrv]], 
						{"comboSize":10, "comboWidth": 120}, 
						"none");
				ragrid.cells(c, idxMETA).setBgColor(colored);
				//search
				ragrid.cells(c, idxSEARCH).setBgColor(colored);
				ragrid.setCellExcellType(c,idxSEARCH,"ch");
				break;
			case "datetime":
				//width
				ragrid.cells(c, idxWIDTH).setValue(130);
				//align
				ragrid.grid_bindCombo(c, idxALIGN, 
						[["left", fmd_i18n_modules.dhxgrid.enualign_left],["right",fmd_i18n_modules.dhxgrid.enualign_right],["center",fmd_i18n_modules.dhxgrid.enualign_center]], 
						{"comboSize":10, "comboWidth": 120}, 
						"center");
				//sorting
				ragrid.grid_bindCombo(c, idxSORT, 
						[["na", fmd_i18n_modules.dhxgrid.enusort_no],["str",fmd_i18n_modules.dhxgrid.enusort_str]], 
						{"comboSize":10, "comboWidth": 120}, 
						"str");
				//format
				ragrid.grid_bindCombo(c, idxFORMAT, [["date",fmd_i18n_modules.datepicker.format_date]], 
						{"comboSize":10, "comboWidth": 120}, 
						"date");
				ragrid.cells(c, idxFORMAT).setBgColor(colored);
				break;
			case "int":
				//width
				ragrid.cells(c, idxWIDTH).setValue(60);
				//align
				ragrid.grid_bindCombo(c, idxALIGN, 
						[["left", fmd_i18n_modules.dhxgrid.enualign_left],["right",fmd_i18n_modules.dhxgrid.enualign_right],["center",fmd_i18n_modules.dhxgrid.enualign_center]], 
						{"comboSize":10, "comboWidth": 120}, 
						"right");
				//sorting
				ragrid.grid_bindCombo(c, idxSORT, 
						[["na", fmd_i18n_modules.dhxgrid.enusort_no],["int",fmd_i18n_modules.dhxgrid.enusort_int]], 
						{"comboSize":10, "comboWidth": 120}, 
						"int");
				//meta
				ragrid.grid_bindCombo(c, idxMETA, 
						[["none", fmd_i18n_modules.dhxgrid.none],["dataprovider-dict", fmd_i18n_modules.dhxgrid.dict],["dataprovider-restsrv",fmd_i18n_modules.dhxgrid.restsrv]], 
						{"comboSize":10, "comboWidth": 120}, 
						"none");
				ragrid.cells(c, idxMETA).setBgColor(colored);
				break;
			case "number":
				//width
				ragrid.cells(c, idxWIDTH).setValue(60);
				//align
				ragrid.grid_bindCombo(c, idxALIGN, 
						[["left", fmd_i18n_modules.dhxgrid.enualign_left],["right",fmd_i18n_modules.dhxgrid.enualign_right],["center",fmd_i18n_modules.dhxgrid.enualign_center]], 
						{"comboSize":10, "comboWidth": 120}, 
						"right");
				//sorting
				ragrid.grid_bindCombo(c, idxSORT, 
						[["na", fmd_i18n_modules.dhxgrid.enusort_no],["int",fmd_i18n_modules.dhxgrid.enusort_int]], 
						{"comboSize":10, "comboWidth": 120}, 
						"int");
				break;
			case "text":
				//width
				ragrid.cells(c, idxWIDTH).setValue(100);
				//align
				ragrid.grid_bindCombo(c, idxALIGN, 
						[["left", fmd_i18n_modules.dhxgrid.enualign_left],["right",fmd_i18n_modules.dhxgrid.enualign_right],["center",fmd_i18n_modules.dhxgrid.enualign_center]], 
						{"comboSize":10, "comboWidth": 120}, 
						"left");
				//sorting
				ragrid.grid_bindCombo(c, idxSORT, 
						[["na", fmd_i18n_modules.dhxgrid.enusort_no],["int",fmd_i18n_modules.dhxgrid.enusort_int],["str",fmd_i18n_modules.dhxgrid.enusort_str]], 
						{"comboSize":10, "comboWidth": 120}, 
						"str");
				break;
		}
	}
	
	//bind onCellChanged
	ragrid.attachEvent("onCellChanged", function(rid,cInd,nv){
		if (cInd==idxMETA && nv) {
			if (nv=="none") {
				ragrid.setCellExcellType(rid,idxMETASOURCE,"ro");
				ragrid.cells(rid, idxMETASOURCE).setBgColor(colorro);
				ragrid.cells(rid, idxMETASOURCE).setAttribute("validate", null);
				if ("string"==ragrid.cells(rid, idxTYPE).getValue()) {//string并且不是字典类，支持模糊搜索
					ragrid.cells(rid, idxSEARCH).setBgColor(colored);
					ragrid.setCellExcellType(rid,idxSEARCH,"ch");
				}
			} else {
				if (nv=='dataprovider-dict') {
					ragrid.setCellExcellType(rid,idxMETASOURCE,"btnex");
					ragrid.cells(rid,idxMETASOURCE).setConfig({"displayValue":"displayValue",
						"onclick":function(rId,cId){fmdmeta_prop.func.selectDict(rId,cId,ragrid)}});
					ragrid.cells(rid,idxMETASOURCE).setValue(null);
					ragrid.cells(rid, idxMETASOURCE).setAttribute("validate", "NotEmptyObject");
				} else {
					ragrid.setCellExcellType(rid,idxMETASOURCE,"btnex");
					ragrid.cells(rid,idxMETASOURCE).setConfig({"displayValue":"displayValue",
						"onclick":function(rId,cId){fmdmeta_prop.func.selectService(rId,cId,ragrid)}});
					ragrid.cells(rid,idxMETASOURCE).setValue(null);
					ragrid.cells(rid, idxMETASOURCE).setAttribute("validate", "NotEmptyObject");
				}
				ragrid.cells(rid, idxSEARCH).setBgColor(colorro);
				ragrid.setCellExcellType(rid,idxSEARCH,"roch");
				ragrid.cells(rid,idxSEARCH).setValue(0);
			}
		}
	});
	
	//load existing
	if (MyUtilJs.isEmpty(ov)) return;
	for (var i in ov) {
		if (ragrid.getRowIndex(ov[i].id)==-1) {
			continue;
		}
		ov[i].zh && ragrid.cells(ov[i].id, idxZH).setValue(ov[i].zh);
		ov[i].en && ragrid.cells(ov[i].id, idxEN).setValue(ov[i].en);
		if ("string"==ov[i].type || "int"==ov[i].type) {
			ov[i].meta && ragrid.cells(ov[i].id, idxMETA).setValue(ov[i].meta);
			ov[i].metasource && ragrid.cells(ov[i].id, idxMETASOURCE).setValue(ov[i].metasource);
		}
		ov[i].hidden && ragrid.cells(ov[i].id, idxHIDDEN).setValue(ov[i].hidden);
		ov[i].width && ragrid.cells(ov[i].id, idxWIDTH).setValue(ov[i].width);
		ov[i].align && ragrid.cells(ov[i].id, idxALIGN).setValue(ov[i].align);
		ov[i].sort && ragrid.cells(ov[i].id, idxSORT).setValue(ov[i].sort);
		ov[i].order && ragrid.cells(ov[i].id, idxORDER).setValue(ov[i].order);
		ov[i].format && ragrid.cells(ov[i].id, idxFORMAT).setValue(ov[i].format);
		ov[i].search && ragrid.cells(ov[i].id, idxSEARCH).setValue(ov[i].search);
		ov[i].rv && ragrid.cells(ov[i].id, idxRV).setValue(ov[i].rv);
		ov[i].dv && ragrid.cells(ov[i].id, idxDV).setValue(ov[i].dv);
	}
};

//properties settings for text popupinput
fmdmeta_prop.control.popupinput = {
		//group for element list - basic/composite/custom/extended
		"group" : "basic",
		//control category
		"controlcategory" : "datacontrol",
		//i18n type name
		"i18ntype" : fmd_i18n_el_popupinput,
		//icon in element list, located in images/designer/modules/
		"icon" : "elem_popupinput.png",
		//html code for dragging
		innerhtml_dragging : '<label class="title">'+fmd_i18n_untitled+'</label><span><input class="large" type="text" readonly="readonly" style="padding-right:20px;background:url(\''+resloc+'/static/images/form/designer/prop/finder.png\') no-repeat scroll right center transparent;" /></span>',
		//html code after dropped
		innerhtml_dropped : '<label class="title">'+fmd_i18n_untitled+'</label><span><input class="large" type="text" readonly="readonly" style="padding-right:20px;background:url(\''+resloc+'/static/images/form/designer/prop/finder.png\') no-repeat scroll right center transparent;" /></span>',
		"includes-properties" : {
			"common" : fmdmeta_prop.common.all.properties,
			"controlcommon" : fmdmeta_prop.common.datacontrol.properties
		},
		"properties" : {
			"i18ntype" : {
		    	"name" : fmd_i18n_prop_selectiontype,
		    	"img" : "selection.png",
		    	"cellType" : "ro",
		    	"value" : {"default":fmd_i18n_el_popupinput},
		    	"displayOnly" : true,
		    	"afterProperty" : "id"
		    },
		    "dataprovider" : {
		    	"name" : fmd_i18n_prop_dataprovider,
		    	"img" : "dataprovider.png",
			    "cellType" : {
					"type" : "coro",
					"options":[["",""],
	        					["dataprovider-predefinedpopup", fmd_i18n_modules.popupinput.predefinedpopup]
	        					//,["dataprovider-restsrv", fmd_i18n_prop_restsrv]
									,["dataprovider-modelselect", fmd_i18n_modules.popupinput.modelselect]
	        	                ]
			    },
			    "validator" : "NotEmpty",
				"conditional-sub" : {
					"dataprovider-predefinedpopup" : {
						"dataprovider-predefinedpopup" : {
							"name" : fmd_i18n_modules.popupinput.predefinedpopup,
//							"cellType" : "ed",
							"cellType" : {
    	    				"type" : "btnex",
    	    				"config" : {
    	    						"displayValue" : "displayValue",
    	    	    				"onclick" : fmdmeta_prop.func.selectPopupUrl
    	    	    			}
    	    				},
							"validator" : "NotEmpty"
						}
				    },
				    "dataprovider-restsrv" : {
				    	"dataprovider-restsrv" : {
				    		"name" : fmd_i18n_prop_restsrv,
							"cellType" : {
    	    					"type" : "btnex",
    	    					"config" : {
    	    						"displayValue" : "displayValue",
    	    	    				"onclick" : fmdmeta_prop.func.selectService
    	    	    			}
    	    				},
							"validator" : "NotEmptyObject"
						}
				    },
				    "dataprovider-modelselect" : {
				    	"dataprovider-modelselectmodel" : {
				    		"name" : fmd_i18n_modules.popupinput.modelselectmodel,
				    		/*"cellType" : {
    	    					"type" : "btnex",
    	    					"config" : {
    	    						"displayValue" : "displayValue",
    	    	    				"onclick" : fmdmeta_prop.func.selectModelForModelSelect
    	    	    			}
    	    				},*/
				    		"cellType" : {
								"type" : "coro",
								"options":"fmdmeta_prop.models_list_all" //initialized later, so use a reference here, call eval when use
						    },
						    "value" : {"default":""},
							"validator" : "NotEmpty"
				    	},
				    	"dataprovider-modelselectlist" : {
				    		"name" : fmd_i18n_modules.popupinput.modelselectmodellist,
				    		"cellType" : {
    	    					"type" : "btnex",
    	    					"config" : {
    	    						"displayValue" : "displayValue",
    	    	    				"onclick" : fmdmeta_prop.func.selectModelListForModelSelect
    	    	    			}
    	    				},
							"validator" : "NotEmptyObject"
				    	}
				    }
				},
			    "value" : {"default":""}
		    },
		    "multiple" : {
		    	"name" : fmd_i18n_modules.popupinput.multiple,
		    	"cellType" : "ch",
		    	"value" : {"default":"0"}
		    },
		    "databinding" : {
		    	"name" : fmd_i18n_prop_binding,
		    	"img" : "databinding.png",
		    	"cellType" : "ro",
		    	"displayOnly" : true,
		    	"sub" : {
		    		"databinding-realvalue" : {
		    			"name" : fmd_i18n_prop_binding +"("+ fmd_i18n_prop_realvalue +")",
		    			"img" : "databinding.png",
				    	"cellType" : {
							"type" : "coro",
							"options":"fmdmeta_prop.model_binding_list" //initialized later, so use a reference here, call eval when use
					    },
					    "value" : {"default":""},
				    	"validator" : "NotEmpty"
		    		},
		    		"databinding-displayvalue" : {
		    			"name" : fmd_i18n_prop_binding +"("+ fmd_i18n_prop_displayvalue +")",
		    			"img" : "databinding.png",
				    	"cellType" : {
							"type" : "coro",
							"options":"fmdmeta_prop.model_binding_list" //initialized later, so use a reference here, call eval when use
					    },
					    "value" : {"default":""},
				    	"validator" : "NotEmpty"
		    		}
		    	}
		    },
		    /*"processbinding" : {
		    	"name" : fmd_i18n_prop_pbinding,
		    	"img" : "processbinding.png",
		    	"cellType" : "ro",
		    	"displayOnly" : true,
		    	"sub" : {
		    		"processbinding-realvalue" : {
		    			"name" : fmd_i18n_prop_pbinding +"("+ fmd_i18n_prop_realvalue +")",
		    			"cellType" : "processbinding",
				    	//"validator" : "NotEmpty",
				    	"img" : "processbinding.png"
		    		},
		    		"processbinding-displayvalue" : {
		    			"name" : fmd_i18n_prop_pbinding +"("+ fmd_i18n_prop_displayvalue +")",
		    			"cellType" : "processbinding",
				    	//"validator" : "NotEmpty",
				    	"img" : "processbinding.png"
		    		}
		    	}
		    },*/
		    "validation" : {
		    	"name" : fmd_i18n_prop_valuevalidation,
		    	"img" : "validation.png",
		    	"cellType" : "ro",
		    	"displayOnly" : true,
		    	"sub" : {
		    		"validation-realvalue" : {
				    	"name" : fmd_i18n_prop_valuevalidation+'('+fmd_i18n_prop_realvalue+')',
				    	"img" : "validation.png",
					    "cellType" : "ace_validation",
					    "arguments" : {
							"v" : fmd_i18n_prop_realvalue
						},
						"params" : {
							"require" : "databinding-realvalue",
							"inputindex" : 1	//input index for validation in this component, starts from 0
						},
					    "value" : {"default":""}
				    },
				    "validation-displayvalue" : {
				    	"name" : fmd_i18n_prop_valuevalidation+'('+fmd_i18n_prop_displayvalue+')',
				    	"img" : "validation.png",
					    "cellType" : "ace_validation",
					    "arguments" : {
							"v" : fmd_i18n_prop_displayvalue
						},
						"params" : {
							"require" : "databinding-displayvalue",
							"inputindex" : 0	//input index for validation in this component, starts from 0
						},
					    "value" : {"default":""}
				    }
		    	}
		    },
		    "maxlength" : {
		    	"name" : fmd_i18n_prop_maxlength,
		    	"cellType" : "ed",
		    	"value" : {"default":"10"},
		    	"validator" : "ValidInteger",
		    	"tooltip" : fmd_i18n_modules.input.tip_maxlength
		    },
		    "inputreadonly" : {
		    	"name" : fmd_i18n_modules.popupinput.inputreadonly,
		    	"cellType" : "ch",
		    	"value" : {"default":"0"}
		    }/*,
		    "autocomplete" : {
		    	"name" : fmd_i18n_modules.popupinput.autocomplete,
		    	"cellType" : "ch",
		    	"value" : {"default":"0"},
		    	"conditional-sub" : {
				    "1" : {
				    	"autocomplete-allowcustomvalue" : {
			    			"name" : fmd_i18n_modules.popupinput.allowcustomvalue,
			    			"cellType" : "ch",
			    			"value" : {"default":"0"}
			    		},
				    	"autocomplete-dataprovider" : {
					    	"name" : fmd_i18n_modules.popupinput.autocompletedataprovider,
					    	"img" : "dataprovider.png",
						    "cellType" : {
								"type" : "coro",
								"options":[["acd-dataprovider-restsrv", fmd_i18n_prop_restsrv],
								           ["acd-dataprovider-dict",fmd_i18n_prop_dict]]
						    },
						    "conditional-sub" : {
							    "acd-dataprovider-restsrv" : {
							    	"acd-dataprovider-restsrv" : {
							    		"name" : fmd_i18n_prop_restsrv,
										"cellType" : {
			    	    					"type" : "btnex",
			    	    					"config" : {
			    	    						"displayValue" : "displayValue",
			    	    	    				"onclick" : fmdmeta_prop.func.selectService
			    	    	    			}
			    	    				},
										"validator" : "NotEmptyObject"
									}
							    },
							    "acd-dataprovider-dict" : {
									"acd-dataprovider-dict" : {
										"name" : fmd_i18n_prop_dict,
										"cellType" : {
			    	    					"type" : "btnex",
			    	    					"config" : {
			    	    						"displayValue" : "displayValue",
			    	    	    				"onclick" : fmdmeta_prop.func.selectDict
			    	    	    			}
			    	    				},
										"validator" : "NotEmptyObject"
									}
							    }
							},
							"value" : {"default":"acd-dataprovider-restsrv"}
					    }
				    }
		    	}
		    }*/
		},
		"includes-events" : {
			"common" : fmdmeta_prop.common.all.events,
			"controlcommon" : fmdmeta_prop.common.datacontrol.events
		},
		"events" : {
			"change" : {"name" : fmd_i18n_ev_onchange,
				"arguments" : {
					"e" : fmd_i18n_ev_eventobj,
					"val1" : fmd_i18n_modules.popupinput.ev_change_val1,
					"val2" : fmd_i18n_modules.popupinput.ev_change_val2,
					"val3" : fmd_i18n_modules.popupinput.ev_change_val3
				}
			}
		},
		"onApply" : function() {
			var obj = designer.getSelected();
			var vals = fmdc.version.formdata.propconf[obj.attr("id")];
			obj.find('label').html(vals["i18nname-"+fmdmeta_prop.lang])
				.css("display", (vals["hideLabel"]=='1')?"none":"block");
		},
		"propDhxGridEvents" : {
			"onEditCell" : function(stage,rId,cId,nv,ov) {
				return true;
			},
			"onCellChanged" : function(rId,cId,nv) {
				if (nv && cId==fmdmeta_prop.gridconf.idx.value) {
					if (rId=='dataprovider') {
						//fmdpf_showConditionalSub(rId, nv, fmdmeta_prop.control.popupinput.properties[rId]);
					} else if (rId=='autocomplete') {
						//fmdpf_showConditionalSub(rId, nv, fmdmeta_prop.control.popupinput.properties[rId]);
						fmdmeta_prop.control.popupinput["propDhxGridEvents"].onCellChanged("autocomplete-dataprovider",
								fmdmeta_prop.gridconf.idx.value,
								this.cells("autocomplete-dataprovider", fmdmeta_prop.gridconf.idx.value).getValue());
					} else if (rId=="autocomplete-dataprovider") {
						//fmdpf_showConditionalSub(rId, nv, fmdmeta_prop.control.popupinput.properties.autocomplete["conditional-sub"]["1"][rId]);
					} else if (rId=='databinding-displayvalue') {
						var vals = nv.split(".");
						if (vals && vals.length==2) {
							if (fmdc.models[vals[0]] && fmdc.models[vals[0]].attrs[vals[1]]) {
								if (this.doesRowExist("i18nname-zh")) {
									var zh = this.cells("i18nname-zh", cId).getValue();
									if (!zh || zh==fmd_i18n_untitled) this.cells("i18nname-zh", cId).setValue(fmdc.models[vals[0]].attrs[vals[1]].desc_zh);
								}
								if (this.doesRowExist("i18nname-en")) {
									var en = this.cells("i18nname-en", cId).getValue();
									if (!en || en=='Untitled') this.cells("i18nname-en", cId).setValue(fmdc.models[vals[0]].attrs[vals[1]].desc_en);
								}
							} else {
								this.cells(rId,cId).setValue('');
							}
						}
					} else if (rId=='databinding-realvalue') {
						var vals = nv.split(".");
						if (vals && vals.length==2) {
							if (!fmdc.models[vals[0]] || !fmdc.models[vals[0]].attrs[vals[1]]) {
								this.cells(rId,cId).setValue('');
							}
						}
					}
				}
			}
		}
	};